package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.api.service.ReportModelApiService;
import com.yixun.qfbao.apidto.CheckPremisesNameReqDto;
import com.yixun.qfbao.apidto.CheckPremisesNameResDto;
import com.yixun.qfbao.apidto.GetReportModelContentResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.CheckPremisesNameReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CheckPremisesNameHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(CheckPremisesNameHander.class);
    @Autowired
    private PremisesApiService premisesApiService;
    @Autowired
    private LoginUtils loginUtils;

    @SuppressWarnings("rawtypes")
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        CheckPremisesNameReqVo req = (CheckPremisesNameReqVo)reqDto;
        CheckPremisesNameReqDto reqDto1 = req.getParams();
        BaseResponseDTO<CheckPremisesNameResDto> res = new BaseResponseDTO<>();
        CheckPremisesNameResDto resDto = new CheckPremisesNameResDto();
        try {
            PartnerInfo partnerInfo = loginUtils.getUser(reqDto1.getUserId());
            if (partnerInfo == null) {
                res.setResult(ResultEnum.FAIL.getNo());
                res.setErrorMsg("未获取到用户信息");
                return res;
            }
            reqDto1.setMerchantId(partnerInfo.getHigherid());
            resDto = premisesApiService.checkPremisesName(reqDto1);
        } catch (Exception e) {
            logger.error("CheckPremisesNameHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(resDto.getResultMsg());
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
